package com.itheima.controller.v1;

import com.itheima.common.R;
import com.itheima.controller.v1.api.AssignRecordControllerApi;
import com.itheima.dto.AssignRecordDto;
import com.itheima.pojo.TbAssignRecord;
import com.itheima.service.TbAssignRecordService;
import com.itheima.service.TbBusinessTrackRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/assign")
@Slf4j
public class AssignRecordController implements AssignRecordControllerApi {
    @Autowired
    private TbAssignRecordService tbAssignRecordService;

    @GetMapping("/page")
    @Override
    public R pageAssign(@RequestBody AssignRecordDto assignRecordDto) {
        //1.转派信息分页回显 6个搜索条件
        return tbAssignRecordService.page(assignRecordDto);
    }

    @GetMapping("/{id}")
    @Override
    public R getById(@PathVariable Long id) {
        //2.转派详情
        // 2.1回显具体类型:前端判断
        // 2.2详情:计数 相关类型单子计数
        // 2.3部门:查部门表
        return tbAssignRecordService.getById(id);
    }

    @PostMapping("/{userId}")
    @Override
    public R update(@RequestBody List<TbAssignRecord> AssignList, @PathVariable Long userId) {
        //3.转派处理(批量) 批量大小阈值3(前端)
        //3.1 更新所属人信息
        //3.2 更新分配人为当前登录人
        //3.3 自动分配下次跟进时间
        return tbAssignRecordService.updateList(AssignList,userId);
    }
}
